package com.ousi.wx.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ousi.wx.common.CommonResult;
import com.ousi.wx.controller.form.SelectLotusByPageForm;
import com.ousi.wx.service.LotusPictureService;
import com.ousi.wx.util.PageUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/lotus/picture")
@Tag(name = "LotusPictureController", description = "品种信息管理接口")
@Slf4j
public class LotusPictureController {
    @Autowired
    private LotusPictureService lotusPictureService;

    @PostMapping("/selectConditionByPage")
    @Operation(summary = "分页显示品种信息接口")
    public CommonResult selectConditionByPage(@RequestBody @Valid SelectLotusByPageForm form) {
        Map param = BeanUtil.beanToMap(form);
        int page = form.getPage();
        int length = form.getLength();
        int start = (page - 1) * length;
        param.put("start", start);
        PageUtils pageUtils = lotusPictureService.selectConditionByPage(param);
        return CommonResult.ok().put("result", pageUtils);
    }
}
